

package MaintMenu.VenPricingUpdMasterFiles;

import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TYGtx {

    public TYGtx() {
        int cc=0;

        //create statement object
        SQLUpdStm stm = new SQLUpdStm();

        String
                tableA, tableB,
                onA,onB,
                whereA,whereB,whereoperator,

                fieldA1,fieldB1,
                fieldA2,fieldB2,
                fieldA3,fieldB3,
                fieldA4,fieldB4,
                fieldA5,fieldB5,
                fieldA6,fieldB6,
                fieldA7,fieldB7,
                fieldA8,fieldB8,
                fieldA9,fieldB9,
                fieldA10,field10;
        int filesToUpdate=1;
            while (filesToUpdate<=3){
    
    
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String dataSourceName = "dbLI";
                String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
                Connection conli = DriverManager.getConnection(dbURL, "", "");
    
    
                String st[] = new String[2];
    
    
    
                 /* update mirror master file */
                whereA="";
                whereB="";
                whereoperator="";
                tableA =    "BCMAST";
                tableB =    "_costTYGTX"+filesToUpdate;
                onA=        "partlink";
                onB=        "[PartsLink #]";

                fieldA1=    "part_no";       //part_no  (oem#)
                fieldB1=    "[OE #]";

                fieldA2=    "TX_NO";       //Vendor Part #
                fieldB2=    "[TYGP #]";

                fieldA3=    "TX_PRC";      //Vendor Price to DNK
                fieldB3=    "[DNK $]";

    //            fieldA4=    "TX_PKG";        //There are no field for TX_PKG
    //            fieldB4=    "ROW";
                st[0] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3);
    //            System.out.println(st[0]);

                             /* update Cooling master file */
                whereA="";
                whereB="";
                whereoperator="";
                tableA =    "coolngm";
                tableB =    "_costTYGTX"+filesToUpdate;
                onA=        "partlink";
                onB=        "[PartsLink #]";
    
                fieldA1=    "part_no";       //part_no  (oem#)
                fieldB1=    "[OE #]";
    
                fieldA2=    "TX_TYGNO";       //Vendor Part #
                fieldB2=    "[TYGP #]";
    
                fieldA3=    "TX_TYGPRC";      //Vendor Price to DNK
                fieldB3=    "[DNK $]";
    
    //            fieldA4=    "TX_TYGPKG";   //Disable for Domestic purchases
    //            fieldB4=    "ROW";
                st[1] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3);
    //            System.out.println(st[1]);


                for (int x=0; x<st.length;x++){
                    Statement stli = conli.createStatement();

                    try {

//                        System.out.println("Script :"+x);
//                        System.out.println(st[x]);
                        int rowsupdated = stli.executeUpdate(st[x]);
                        System.out.print("TRU : "+rowsupdated+"\t");
                        //JOptionPane.showOptionDialog(null, "Statement : " + st[x] + "\n\nTotal record Updated : " + rowsupdated, "Update Complete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);

                        cc++;
                        if (cc==4){
                            System.out.println("");
                            cc=0;
                        }

                    }catch(SQLException er) {
                        er.printStackTrace();
                    }stli.close();
                }filesToUpdate++;
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    
}